package leetcode;

import common.BTNode;

public class 计算所有根节点到叶子节点数字之和 {

	public int sumNumbers(BTNode root) {
        if(root==null)return 0;
        return sumNumbers(root,0);
    }

	private int sumNumbers(BTNode root, int i) {
		if(root==null) return 0;
		i = i*10 + root.value;
		if(root.left==null && root.right==null) {
			return i;
		}
		return sumNumbers(root.left,i) + sumNumbers(root.right,i);
	}
}
